package com.zr.gdms.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zr.gdms.model.User;
import com.zr.gdms.service.AdminTeacherService;
import com.zr.gdms.service.LoginService;
import com.zr.gdms.serviceimpl.AdminTeacherServiceImpl;
/**
 * 增加教师
 * @author 李培宁
 *
 */
import com.zr.gdms.serviceimpl.LoginServiceImpl;
public class InsertTeacherControllerLPN extends HttpServlet{

	AdminTeacherService ats = new AdminTeacherServiceImpl();
	LoginService ls = new LoginServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf8");
		
		String uname = req.getParameter("uname");
		String upsw = req.getParameter("upsw");
		String tname = req.getParameter("tname");
		String tage = req.getParameter("tage");
		String tdepart = req.getParameter("tdepart");
		String tprofe = req.getParameter("tprofe");
		String tsex = req.getParameter("tsex");
		String ttel = req.getParameter("ttel");
		PrintWriter pw = resp.getWriter();
		
		boolean flag1 = ats.insertUserByTeacher(uname, upsw);
		User u = ls.findUserByUnameAndUpsw(uname, upsw);
		int uid = u.getUid();
		boolean flag2 = ats.insertTeacher(tname, tage, tdepart, tprofe, tsex, ttel,uid);
		if (flag1) {
			if (flag2) {
				pw.write("1");
				
			} else {
				pw.write("0");
			}
		} else {
			pw.write("0");
		}
		pw.flush();
		pw.close();
	}
	
}
